<template>
  <data-row :col="4">
    <template #default="{ span }">
      <el-col v-for="(item,index) in data" :key="index" v-bind="span">
        <el-card shadow="house" class="panel-row app-tap app-margin-bottom-interval" @click="tapPanel(item,index)" :style="{backgroundColor:item.color}">
          <div class="panel-item" :style="{borderColor:item.color}">
            <div class="panel-icon" :style="{backgroundColor:item.color}">
              <svg-icon color="#ffffff" size="54" :name="item.icon"></svg-icon>
            </div>
            <div class="panel-info">
              <p class="panel-title">{{ item.name }}</p>
              <p class="panel-info" v-html="item.info"></p>
            </div>
          </div>
        </el-card>
      </el-col>
    </template>
  </data-row>
</template>
<script lang="ts">
import {defineComponent, PropType} from 'vue'

export type DataPanelItem = {
  icon: string, color: string, name: string, info: string
}

export default defineComponent({
  name: 'DataPanel',
  emits: {
    tap: (item: DataPanelItem, index: number) => true
  },
  props: {
    data: {
      type: Array as PropType<Array<DataPanelItem>>,
      required: true
    }
  },
  setup(props, {emit}) {
    return {
      tapPanel(item: DataPanelItem, index: number) {
        emit('tap', item, index)
      }
    }
  }
})
</script>

<style lang="scss" scoped>
.panel-row {
  padding: 5px;

  :deep(.el-card__body) {
    padding: 5px 0;
  }

  .panel-item {
    cursor: pointer;
    position: relative;
    height: 82px;
    box-sizing: border-box;
    border: 1px solid;
    border-radius: 4px;

    .panel-icon {
      position: absolute;
      top: 0;
      left: 0;
      display: inline-block;
      width: 54px;
      height: 54px;
      padding: 13px;
      text-align: center;
      vertical-align: middle;
      border-right: 2px dashed rgb(255 255 255 / 50%) !important;

      .svg-icon {
        mix-blend-mode: unset;
      }
    }

    .panel-info {
      margin: 0 10px;
      height: 54px;
      width: calc(100% - 110px);
      padding: 13px 5px;
      position: absolute;
      top: 0;
      left: 80px;

      p {
        all: initial;
        display: block;
        text-align: center;
      }

      .panel-title {
        font-size: 16px;
        font-weight: bold;
        color: #ffffff;
        mix-blend-mode: unset;
      }

      .panel-info {
        margin-top: 10px;
        font-size: 14px;
        font-weight: bold;
        color: #ffffff;
        mix-blend-mode: unset;
      }
    }
  }
}
</style>